home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994…tember: Reference Library / Dev.CD Sep 94.toast / Periodicals / develop / develop Issue 17 / develop 17 code / PwrPC Standalone Code / WDEF / wdef.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-22  |  4.7 KB  |  241 lines  |  [TEXT/MPS ]

  1. #include <Quickdraw.h>
  2. #include <Windows.h>
  3. #include <Memory.h>
  4.  
  5. #define LOWORD(x) (x & 0x0000FFFF)
  6. #define HIWORD(x) ((x>>16) & 0x0000FFFF)
  7.  
  8. /* 
  9.     prototypes
  10. */
  11.  
  12. pascal long main(short varCode,WindowPeek theWindow,short message,long param);
  13. long DoDrawWindow(short varCode,WindowPeek theWindow,long param);
  14. long DoHit(short varCode,WindowPeek theWindow,long param);
  15. long DoCalcRgns(short varCode,WindowPeek theWindow,long param);
  16. long DoNew(short varCode,WindowPeek theWindow,long param);
  17. long DoDispose(short varCode,WindowPeek theWindow,long param);
  18. long DoGrow(short varCode,WindowPeek theWindow,long param);
  19. long DoDrawGIcon(short varCode,WindowPeek theWindow,long param);
  20. void GetTitleRect(WindowPeek theWindow,Rect *r);
  21. void GetGoAwayRect(WindowPeek theWindow,Rect *r);
  22. void GetChangerRect(WindowPeek theWindow,Rect *r);
  23. void DrawTitleBar(WindowPeek theWindow);
  24. void DrawWindowTitle(WindowPeek theWindow);
  25. void DrawGoAwayBox(WindowPeek theWindow);
  26. void HiliteGoAwayBox(WindowPeek theWindow);
  27.  
  28. pascal long main(short varCode,WindowPeek theWindow,short message,long param)
  29. {
  30.     long result;
  31.     
  32.     switch(message)
  33.     {
  34.         case wDraw:
  35.             result = DoDrawWindow(varCode,theWindow,param);
  36.             break;
  37.         case wHit:
  38.             result = DoHit(varCode,theWindow,param);
  39.             break;
  40.         case wCalcRgns:
  41.             result = DoCalcRgns(varCode,theWindow,param);
  42.             break;
  43.         case wNew: 
  44.             result = DoNew(varCode,theWindow,param);
  45.             break;
  46.         case wDispose: 
  47.             result = DoDispose(varCode,theWindow,param);
  48.             break;
  49.         case wGrow:
  50.             result = DoGrow(varCode,theWindow,param);
  51.             break;
  52.         case wDrawGIcon:
  53.             result = DoDrawGIcon(varCode,theWindow,param);
  54.             break;
  55.         default:
  56.             result = 0;
  57.             break;
  58.     }
  59.     return result;
  60. }
  61.  
  62. long DoDrawWindow(short varCode,WindowPeek theWindow,long param)
  63. {
  64.     short code;
  65.  
  66.     code = LOWORD(param);
  67.     
  68.     if(theWindow->visible)
  69.     {
  70.         switch(code)
  71.         {
  72.             case 0:    
  73.                 // draw entire window frame
  74.                 DrawTitleBar(theWindow);
  75.                 if(theWindow->hilited)
  76.                     DrawGoAwayBox(theWindow);
  77.                 FrameRgn(theWindow->strucRgn);
  78.                 break;
  79.             case wInGoAway:
  80.                 HiliteGoAwayBox(theWindow);
  81.                 break;
  82.             default:
  83.                 break;
  84.         }
  85.     }
  86.     return 0;
  87. }
  88.  
  89. long DoHit(short varCode,WindowPeek theWindow,long param)
  90. {
  91.     Point p;
  92.     Rect r;
  93.     long result = wNoHit;
  94.     Rect titleRect;
  95.     
  96.     p.h = LOWORD(param);
  97.     p.v = HIWORD(param);
  98.     
  99.     if(PtInRgn(p,theWindow->contRgn))
  100.     {
  101.         result =  wInContent;
  102.     }
  103.     else if(PtInRgn(p,theWindow->strucRgn))
  104.     {
  105.         GetTitleRect(theWindow,&titleRect);
  106.         if(PtInRect(p,&titleRect))
  107.             result = wInDrag;
  108.         if(theWindow->hilited)
  109.         {
  110.             GetGoAwayRect(theWindow,&r);
  111.             if(PtInRect(p,&r))
  112.                 result =  wInGoAway;
  113.         }
  114.     }
  115.     return result;
  116. }
  117.  
  118. long DoCalcRgns(short varCode,WindowPeek theWindow,long param)
  119. {
  120.     Rect tRect;
  121.     Rect pRect;
  122.     Rect bRect;
  123.     
  124.     pRect = theWindow->port.portRect;
  125.     bRect = theWindow->port.portBits.bounds;
  126.     OffsetRect(&pRect,-bRect.left,-bRect.top);
  127.     
  128.     OpenRgn();
  129.     FrameRect(&pRect);
  130.     CloseRgn(theWindow->contRgn);
  131.     
  132.     GetTitleRect(theWindow,&tRect);
  133.     InsetRect(&pRect,-1,-1);
  134.     pRect.top -= tRect.bottom - tRect.top - 1;
  135.     OpenRgn();
  136.     FrameRect(&pRect);
  137.     CloseRgn(theWindow->strucRgn);
  138.  
  139.     return 0;
  140. }
  141.  
  142. long DoNew(short varCode,WindowPeek theWindow,long param)
  143. {
  144.     theWindow->spareFlag = true;
  145.     theWindow->goAwayFlag = false;
  146.     return 0;
  147. }
  148.  
  149. long DoDispose(short varCode,WindowPeek theWindow,long param)
  150. {
  151.     return 0;
  152. }
  153.  
  154. long DoGrow(short varCode,WindowPeek theWindow,long param)
  155. {
  156.     return 0;
  157. }
  158.  
  159. long DoDrawGIcon(short varCode,WindowPeek theWindow,long param)
  160. {
  161.     return 0;
  162. }
  163.  
  164. void GetTitleRect(WindowPeek theWindow,Rect *r)
  165. {
  166.     FontInfo fInfo;
  167.     
  168.     GetFontInfo(&fInfo);
  169.     *r = (**theWindow->strucRgn).rgnBBox;
  170.     r->bottom = r->top+fInfo.ascent+fInfo.descent+4;
  171. }
  172.  
  173. void GetGoAwayRect(WindowPeek theWindow,Rect *r)
  174. {
  175.     GetTitleRect(theWindow,r);
  176.     r->top += 4;
  177.     r->left += 8;
  178.     r->bottom = r->top + 11;
  179.     r->right = r->left + 11;
  180. }
  181.  
  182. void DrawTitleBar(WindowPeek theWindow)
  183. {
  184.     Rect r;
  185.     Pattern p;
  186.  
  187.     p.pat[0]=0x88;
  188.     p.pat[1]=0x44;
  189.     p.pat[2]=0x22;
  190.     p.pat[3]=0x11;
  191.     p.pat[4]=0x88;
  192.     p.pat[5]=0x44;
  193.     p.pat[6]=0x22;
  194.     p.pat[7]=0x11;
  195.     
  196.     PenNormal();
  197.     GetTitleRect(theWindow,&r);
  198.     FrameRect(&r);
  199.     InsetRect(&r,1,1);
  200.     EraseRect(&r);
  201.     if(theWindow->hilited)
  202.     {
  203.         FillRect(&r,(ConstPatternParam)&p);
  204.     }
  205. }
  206.  
  207. void DrawWindowTitle(WindowPeek theWindow)
  208. {
  209.     FontInfo fInfo;
  210.     short    tLeftMargin;
  211.     Rect r;
  212.     
  213.     GetFontInfo(&fInfo);
  214.     GetTitleRect(theWindow,&r);
  215.     tLeftMargin = (r.right - r.left - theWindow->titleWidth)/2;
  216.     MoveTo(r.left + tLeftMargin,r.top + fInfo.ascent + 2);
  217.     HLock((Handle)theWindow->titleHandle);
  218.     DrawString(*theWindow->titleHandle);
  219.     HUnlock((Handle)theWindow->titleHandle);
  220. }
  221.  
  222. void DrawGoAwayBox(WindowPeek theWindow)
  223. {
  224.     Rect r;
  225.     
  226.     GetGoAwayRect(theWindow,&r);
  227.     FrameRect(&r);
  228.     InsetRect(&r,1,1);
  229.     EraseRect(&r);
  230. }
  231.  
  232. void HiliteGoAwayBox(WindowPeek theWindow)
  233. {
  234.     Rect r;
  235.     
  236.     GetGoAwayRect(theWindow,&r);
  237.     FrameRect(&r);
  238.     InsetRect(&r,1,1);
  239.     InvertRect(&r);
  240. }
  241.